package com.flextribe.display {
	import flash.display.DisplayObject;

	public class TribeAsset extends TribeSprite {

		private var _asset:DisplayObject;

		public function get assetClass():Class  {
			return this._assetClass;
		}
		public function set assetClass(value:Class):void  {
			this._assetClass = value;
			if(_asset != null && this.contains(_asset)) this.removeChild(_asset);
			_asset = null;
			createChildren();
		}
		private var _assetClass:Class;

		public function TribeAsset(assetClass:Class = null) {
			this._assetClass = assetClass;
			super(true);
		}
		override public function createChildren():void{
			if(_assetClass != null) {
				_asset = new _assetClass();
				this.addChild(_asset);
			}
		}
		
		override public function setSize(width:Number, height:Number):void{
			//super.setSize(width, height);
			if(_asset){
				_asset.width = width;
				_asset.height = height;
			}
			_width = width;
			_height = height;
		}
		override public function set width(value:Number):void{
			if(_asset)_asset.width = value; 
			_width = value;	
		}
		override public function set height(value:Number):void{
			if(_asset) _asset.height = value; 
			_height = value;
		}
		override public function get width():Number{
			return _asset ? _asset.width : 0;
		}
		override public function get height():Number{
			return _asset ? _asset.height : 0;
		}
		override public function destroy():void{
			if(_asset && this.contains(_asset)) this.removeChild(_asset);
			_asset = null;
		}
	}
}
